package cn.ly.design.action.clazz;
/**
 * 命令模式的目的就是达到命令的发出者和执行者之间解耦，实现请求和执行分开，
 * Struts其实就是一种将请求和呈现分离的技术，其中必然涉及命令模式的思想！
 * @author liuyu
 *
 */
public class CommandTest {
	public static void main(String[] args){
		Operator operator = new Operator();
		Command command = new MyCommand(operator);
		Invoker invoker = new Invoker(command);
		invoker.action();
	}

}

class Invoker {  
    private Command command;  
    public Invoker(Command command) {  
        this.command = command;  
    }
    public void action(){  
        command.execute();  
    }  
}  

interface Command{
	Operator operator = null;
	void execute();
	default Operator getOperator(){
		return operator;
	}
}

class MyCommand implements Command{
	
	public MyCommand(Operator operator){
		getOperator();
	}
	
	@Override
	public void execute() {
		operator.action();
	}
}



class Operator{
	public void action(){
		System.out.println("exe command");
	}
}